<script setup>
import { ref } from 'vue'

const artStyles = [
  { id: 'watercolor', name: '水彩风格', icon: '🎨' },
  { id: 'abstract', name: '抽象艺术', icon: '🌈' },
  { id: 'pixel', name: '像素艺术', icon: '👾' },
  { id: 'geometric', name: '几何图形', icon: '🔷' }
]

const colorPalettes = [
  { id: 'warm', name: '温暖色系', colors: ['#FF6B6B', '#FFA06B', '#FFD93D'] },
  { id: 'cool', name: '冷静色系', colors: ['#4ECDC4', '#64B5F6', '#7C5CFF'] },
  { id: 'pastel', name: '柔和色系', colors: ['#FFB5C2', '#B5DEFF', '#C3FFB5'] },
  { id: 'dark', name: '深沉色系', colors: ['#2C3E50', '#34495E', '#4A5568'] }
]

const artSettings = ref({
  style: 'watercolor',
  palette: 'warm',
  complexity: 50,
  intensity: 50,
  animation: false
})

const generatedArt = ref(null)
const isGenerating = ref(false)

const generateArt = () => {
  isGenerating.value = true
  // 模拟生成过程
  setTimeout(() => {
    generatedArt.value = 'https://placekitten.com/800/500'
    isGenerating.value = false
  }, 2000)
}
</script>

<template>
  <div class="art-creator">
    <div class="creator-container">
      <!-- 左侧控制面板 -->
      <div class="controls-panel mood-card">
        <h2 class="section-title">艺术创作</h2>
        
        <!-- 风格选择 -->
        <div class="control-section">
          <h3>选择风格</h3>
          <div class="style-grid">
            <button 
              v-for="style in artStyles"
              :key="style.id"
              :class="['style-btn mood-btn', artSettings.style === style.id ? 'active' : '']"
              @click="artSettings.style = style.id"
            >
              <span class="style-icon">{{ style.icon }}</span>
              {{ style.name }}
            </button>
          </div>
        </div>

        <!-- 配色方案 -->
        <div class="control-section">
          <h3>配色方案</h3>
          <div class="palette-grid">
            <button 
              v-for="palette in colorPalettes"
              :key="palette.id"
              :class="['palette-btn', artSettings.palette === palette.id ? 'active' : '']"
              @click="artSettings.palette = palette.id"
            >
              <div class="color-preview">
                <div 
                  v-for="(color, index) in palette.colors"
                  :key="index"
                  class="color-dot"
                  :style="{ backgroundColor: color }"
                ></div>
              </div>
              <span>{{ palette.name }}</span>
            </button>
          </div>
        </div>

        <!-- 参数调节 -->
        <div class="control-section">
          <h3>参数调节</h3>
          <div class="slider-group">
            <div class="slider-control">
              <label>复杂度</label>
              <input 
                v-model="artSettings.complexity"
                type="range"
                min="0"
                max="100"
                class="mood-slider"
              >
              <span>{{ artSettings.complexity }}%</span>
            </div>
            <div class="slider-control">
              <label>强度</label>
              <input 
                v-model="artSettings.intensity"
                type="range"
                min="0"
                max="100"
                class="mood-slider"
              >
              <span>{{ artSettings.intensity }}%</span>
            </div>
          </div>
        </div>

        <!-- 动画效果 -->
        <div class="control-section">
          <div class="animation-toggle">
            <label class="toggle-label">
              <input 
                v-model="artSettings.animation"
                type="checkbox"
                class="toggle-input"
              >
              <span class="toggle-slider"></span>
              动态效果
            </label>
          </div>
        </div>

        <!-- 生成按钮 -->
        <button 
          class="generate-btn mood-btn"
          @click="generateArt"
          :disabled="isGenerating"
        >
          <span>✨</span>
          {{ isGenerating ? '生成中...' : '生成艺术作品' }}
        </button>
      </div>

      <!-- 右侧预览区域 -->
      <div class="preview-panel mood-card">
        <div class="preview-header">
          <h3>预览</h3>
          <div class="preview-actions">
            <button class="mood-btn" v-if="generatedArt">
              <span>💾</span>
              保存
            </button>
            <button class="mood-btn" v-if="generatedArt">
              <span>🔄</span>
              重新生成
            </button>
          </div>
        </div>

        <div class="preview-canvas">
          <template v-if="generatedArt">
            <img :src="generatedArt" alt="生成的艺术作品">
          </template>
          <div v-else-if="isGenerating" class="generating-animation">
            <div class="generating-pulse"></div>
            <p>正在创作中...</p>
          </div>
          <div v-else class="empty-canvas">
            <span class="empty-icon">🎨</span>
            <p>选择参数开始创作</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.art-creator {
  padding: 1rem;
}

.creator-container {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 2rem;
  min-height: 80vh;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.control-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-section h3 {
  color: var(--text-primary);
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.style-btn {
  justify-content: center;
  padding: 1rem;
}

.style-icon {
  font-size: 1.5rem;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.palette-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.palette-btn.active {
  border-color: var(--primary-color);
  background: rgba(124, 92, 255, 0.1);
}

.color-preview {
  display: flex;
  gap: 0.3rem;
}

.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.slider-control {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.mood-slider {
  flex: 1;
  height: 8px;
  -webkit-appearance: none;
  background: #e2e8f0;
  border-radius: 4px;
}

.mood-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--primary-color);
  border-radius: 50%;
  cursor: pointer;
}

.animation-toggle {
  display: flex;
  align-items: center;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  cursor: pointer;
}

.toggle-input {
  display: none;
}

.toggle-slider {
  width: 48px;
  height: 24px;
  background: #e2e8f0;
  border-radius: 12px;
  position: relative;
  transition: all 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: all 0.3s ease;
}

.toggle-input:checked + .toggle-slider {
  background: var(--primary-color);
}

.toggle-input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.generate-btn {
  margin-top: auto;
  padding: 1rem;
  font-size: 1.1rem;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-actions {
  display: flex;
  gap: 1rem;
}

.preview-canvas {
  flex: 1;
  background: #f8f9ff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 500px;
}

.preview-canvas img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty-canvas {
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  display: block;
}

.generating-animation {
  text-align: center;
}

.generating-pulse {
  width: 100px;
  height: 100px;
  background: var(--primary-color);
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 0.8; }
  100% { transform: scale(0.8); opacity: 0.5; }
}
</style> 